
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <?php include "jquery.php" ?>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script>
//this part of the code is for hiding and showing the messages table
        $(document).ready(function(){
$(".flip").click(function(){
    $(".panel").slideToggle("slow");
  });
});
</script>
<style type="text/css">
p.flip
{
cursor: pointer;
margin:0px;
padding:5px;
text-align:center;
background:white;
border:solid 1px #c3c3c3;

}
div.panel
{
height: 300px;
display:none;
overflow: auto;
}
</style>
        <title></title>
</head>
<body>
<?php

//include 'functions.php';
// Connect to the database
session_start();
$member_id= $_SESSION['member_id'];
$dbLink = mysql_connect('localhost', 'root', "");
if(!$dbLink) {
    die("MySQL connection failed");
}

mysql_select_db('mydb');

//query to retrieve all messages where the user is a reciever
$result = mysql_query("SELECT m.first_name, m.last_name, ms.subject, s.message_id FROM member m
         INNER JOIN member_message_member s
         ON (m.member_id = s.member_id1)
         INNER JOIN messages ms ON s.message_id=ms.message_id
            WHERE s.member_id2='$member_id'")or die(mysql_error());

// Check if it was successfull
if($result) {

    $num_results = mysql_num_rows($result);
    // Make sure there are some rows in the database
    if($num_results == 0) {
        echo "<p align='center'>You have no messages.</p>";
    }
    else {
        echo '<p class="flip">Show/Hide Messages</p>';
        echo "<div class='panel'>";
        // Print the top of a table
        echo '<table id="table">
                <tr>
                    <td><b>From</b></td>
                    <td><b>Subject</b></td>
                </tr>';
        // Print each file
        while($row = mysql_fetch_assoc($result)) {

	$update = mysql_query("UPDATE `messages` SET `messages`.`seen` = TRUE WHERE message_id={$row['message_id']}") or die (mysql_error());
            echo "
                <tr>
                    <td>{$row['first_name']}{$row['last_name']}</td>
                    <td><a href='viewMessage.php?message_id={$row['message_id']}'>{$row['subject']}</a></td>
                    <td><a href='deleteM.php?message_id={$row['message_id']}'>delete</a></td>
                </tr>";
        }
        // Close table
        echo '</table>';
        echo '</div>';


     }
}
else
{
    // if connetion to database failed
    echo 'Error! SQL query failed:';
}
// Close the mysql connection
mysql_close($dbLink);
?>
    <script type="text/javascript">
</script>
</body>
</html>
<?php
    $con=mysql_connect('localhost','root','');
    mysql_select_db('mydb');

    //query to retrieve all the oncferences where the user is the creator
    $sql = ("SELECT DISTINCT c.conference_id, c.long_name FROM conference c
            INNER JOIN member_privileges m ON (m.conference_id = c.conference_id)
            WHERE (c.creator_id='$member_id') OR (m.member_id = '$member_id') AND (privileges_id = '2')");
    $result = mysql_query($sql) or die(mysql_error());
    $num_rows=mysql_num_rows($result);
    mysql_close($con);

    //creating the drop down list
    if ($num_rows > 0) {
        echo "<form name='chooseconference' action='choosepeople.php' method='POST'>
    Conference: <select name='conference'>";

            for($i=0;$i<$num_rows;$i++)
            {
                $conference_id=mysql_result($result,$i,0);
                $short_name=mysql_result($result,$i,1);
                echo '<option value="'.$conference_id.'">'.$short_name.'</option>';
            }

   echo  "</select>
    </br>
    <input type='submit' value='Create Message' name='submit' />
</form>";
    }
    else {
        echo "<p align='center'> You are not organizer of any conference to send message </p>";
    }
?>
